package com.redis;

import redis.clients.jedis.Jedis;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @author: sun.hongliang
 * @create: 2018/08/20 15:01
 */
public class RedisTest {
    private static Jedis jedis;

    static {
        jedis = new Jedis("47.98.157.6", 6379);
        jedis.auth("Shl@137961");
    }

    public static void main(String[] args) {
//        jedis.set("test","sunhongliang");

//        System.out.println(jedis.get("test"));
//        System.out.println(jedis.getrange("test", 0, -1));
//        System.out.println(jedis.getSet("test", "sun"));
//        List<String> mget = jedis.mget("tt", "test","eeee");
//        System.out.println(mget);
//        String test = jedis.setex("test", 10, "<sun.hongliang>");
//        System.out.println(test);
//        System.out.println(jedis.setnx("test","sun"));
//        System.out.println(jedis.strlen("test"));
//        System.out.println(jedis.append("test", "test"));
//        System.out.println(jedis.set("lock", "tmp", "XX", "PX", 200000));
//        System.out.println(jedis.setex("lo", 1000, "d"));

//        System.out.println(jedis.hset("myhash", "key", "hashVal"));
//        System.out.println(jedis.hset("myhash", "file1", "hashVal"));
//        System.out.println(jedis.hdel("myhash", "file1"));
//        System.out.println(jedis.hexists("myhash", "key"));
//        System.out.println(jedis.hget("myhash", "key"));
//        System.out.println(jedis.hgetAll("myhash"));
//        Set<String> hkeys = jedis.hkeys("myhash");
//        System.out.println(hkeys);

//        System.out.println("=======================================");
//        System.out.println(jedis.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", Arrays.asList("key1", "key2"), Arrays.asList("val1", "val2")));
//
//        System.out.println(jedis.eval("return redis.call('hexists',KEYS[1],ARGV[1])",
//                Collections.singletonList("myhash"), Collections.singletonList("key")));

        Object myhash = jedis.eval("return redis.call('hexists',KEYS[1],KEYS[2])", 2, "myhash", "key");
        System.out.println(myhash);
    }
}
